<?php

require_once("evalable.php");

class StringObject extends Evalable {

    var $string = null;

    function StringObject($str) {
        if (is_object($str) && get_class($str) == "StringObject") {
            $str = $str->string;
        }
        $this->string = $str;
    }

    function repr() {
        return $this->string;
    }

    function lispeval($env, $args=null) {
        return $this;
    }

    function nullp() {
        if ($this->string == "") {
            return new LogicObject(1);
        } else {
            return new LogicObject(0);
        }
    }

    function getitem($index) {
        return $this->string[$index];
    }

    function getval() {
        return $this->string;
    }

    function cmp($other) {
        if (get_class($this) == get_class($other)) {
            if ($this->string == $other->string) {
                return 0;
            } elseif ($this->string > $other->string) {
                return 1;
            } else {
                return -1;
            }
        } else {
            if ($this->string == $other) {
                return 0;
            } elseif ($this->string > $other) {
                return 1;
            } else {
                return -1;
            }
        }
    }

}

